/**
 * Created by 小润 on 2017/3/27.
 */
$(document).ready(function ()  {
    var ajaxData, shareList, feedId
    var personId=localStorage.getItem("personId");
    var personid=$(".personId").val();
    if(personId!=personid){
        $(".share_btn").css("display","none");
    }
    init();
    //展示新增
    var userId=localStorage.getItem("userId")
    var message=$(".addfamily").val();
    if(personid==personId || userId==1 ){
        $("#add-img").show()
    }else {
        $("#add-img").css("display","none")
        $(".pro_content").css("display","none")
    }


})
//初始化页面
    function init() {
        $.ajax({
            url: '/api/v1/person/details',
            type: "post",
            async: true,
            success: function (data) {
                ajaxData = data;
               // initPage(data);
                // console.log(data.result);
            },

            error: function (msg) {
                //alert('请求失败');
                console.log(msg)
            }
        });
    }

    // function initPage(data) {
    //     //接口暂时不可以
    //
    //     //个人分享列表
    //     //maxId
    //     var maxId = 5;
    //     // listShare(maxId, pageSize, sinceId, tagId, userId)
    // }
    /*$(function(){
        $('#isAlive').on('click',function(){
           var checkedOfAll=$("#isAlive").prop("checked");
           $("#isAlive").prop("checked", checkedOfAll);
           console.log(checkedOfAll)
        })
        var isAutoSend = document.getElementsByName('optionsRadiosinline');
        $(isAutoSend).on('click',function(){
           for (var i = 0; i < isAutoSend.length; i++) {
               if (isAutoSend[i].checked == true) {
                   alert(isAutoSend[i].value);
               }
           }
        })
    })*/
//上传文件

        var filesArray;
        var headUrl=[];
        var inputElement = document.getElementById("loadImage");       //家族头像
        inputElement.addEventListener("change", handleFiles, false);
        function handleFiles() {
            filesArray = this.files;
            //图片上传预览
            var imgObjPreview=document.getElementById("preview");
            if(filesArray[0])
            {
                //火狐下，直接设img属性
                imgObjPreview.style.display = 'block';
                imgObjPreview.style.width = '60px';
                imgObjPreview.style.height = '60px';
                //imgObjPreview.src = docObj.files[0].getAsDataURL();

                //火狐7以上版本不能用上面的getAsDataURL()方式获取，需要一下方式
                imgObjPreview.src = window.URL.createObjectURL(filesArray[0]);
            }
            upload();
        }
        function upload() {
            // console.log(filesArray[0]);
            // sendFile(filesArray[0])
            for (var i = 0; i < filesArray.length; i++) {
                sendFile(filesArray[i])
            }
        }
        function sendFile(file) {
            console.log(typeof file)
            $('.load-status').css('display','block');
            $('#editSuccess').attr('disabled','disabled').css('cursor','not-allowed');
            var url = "/api/v1/upload/";    //文件上传接口地址 ?type=3&id=1
            var xhr = new XMLHttpRequest();
            var fd = new FormData();
            xhr.open("post", url, true);
            xhr.onreadystatechange = function () {
                if (xhr.readyState == 4 && xhr.status == 200) {
                    $('.load-status').css('display','none');
                    $('#editSuccess').removeAttr('disabled').css('cursor','auto ');
                    var imgUrl = xhr.responseText;
                    headUrl.push(imgUrl);
                    $(".photo-load").attr("src","/static/h5/images/photo-load.png");
                    $('#imgContainer li').remove();
                    showImg(headUrl);
                }
            };
            fd.append('file', file);
            xhr.send(fd);
        }
        function showImg(headUrl) {
            for(var i=0;i<headUrl.length;i++){
              //  console.log(headUrl.length);
                //console.log(headUrl[i]);
                var li = $("<li></li>");
                var img = $("<img src='"+headUrl[i]+"'/>");
                var span = $("<span class='img-close'>x</span>");
                li.append(img);
                li.append(span);
                $('#imgContainer').append(li);
            }
            $('#imgContainer').on('click','.img-close',function(){
                $(this).parent().remove();
            })
        }
//新增人物编辑
  /*  $('#sureEdit').click(pasonnalEdit);
    function pasonnalEdit(){
        var checked,sex;
        var userId;   //自身ID
        var familyName = $('#familyName').val();    //获取姓氏
        var name = $('#name').val();                //获取名字
        var brithday = $('#processTime1').val();    //生日
        var tel = $('#tel').val();                  //手机号（非必填）
        var wx = $('#wx').val();                    //微信号（非必填）
        //判断是否健在
        $('#isAlive').on('click',function(){
            checked=$("#isAlive").prop("checked");
            $("#isAlive").prop("checked", checked);    //checked返回true表示在世，false表示去世
        });
        //判断性别
        var isAutoSend = document.getElementsByName('optionsRadiosinline');
        $(isAutoSend).on('click',function(){
            for (var i = 0; i < isAutoSend.length; i++) {
                if (isAutoSend[i].checked == true) {
                    sex = isAutoSend[i].value;            //sex为性别男或女
                }
            }
        });

        //判断人物信息是否输入为空
        if (familyName == "" || name == "" || brithday == "") {
            $('#showerror p').text("请完善人物信息！");
            $("#showerror").fadeIn(2000, function () {
                $(this).fadeOut(2000);
            });
            return false;
        }

        getEdit(userId,familyName,name,brithday,sex,checked,tel,wx);

    }
    function getEdit(userId,familyName,name,brithday,sex,checked,tel,wx){
        var data = {
            "userId": userId,
            "familyName": familyName,
            "name": name,
            "brithday": brithday,
            "sex": sex,
            "checked": checked,
            "tel": tel,
            "wx": wx
        };
        $.ajax({
            type: "get",
            url: 'ddd',      //编辑人物接口
            data: data,
            success: function (data) {
                $('#showerror p ').text('人物添加成功');
                $("#showerror").fadeIn(1500, function () {
                    $(this).fadeOut(1500, function () {
                        return false;
                    });
                })
            },
            error: function (msg) {
                alert("请求失败！");
                console.log(msg)
            }
        });
    }*/

//创建历程
    $('#editSuccess').click(function(){
        var processContent = $('#processContent').val();   //获取历程内容
      //  var processTime = $('#processTime').val();         //历程发生时间
        var userId = localStorage.getItem("userId");
        var tagId = 5;//死的  历程类型id
       // var latitude = -0.79769313486232e308;        //position.coords.latitude,
        //var  longitude = +0.79769313486232e308;
        var pics=headUrl;
        //判断人物信息是否输入为空
        if (processContent.trim() == "") {
            $('#showerror1 p').text("请输入历程内容！");
            $("#showerror1").fadeIn(2000, function () {
                $(this).fadeOut(2000);
            });
            return false;
        }
        processEdit(userId,processContent,tagId,pics);
    });
    function  processEdit(userId,processContent,tagId,pics){
        console.log(pics)
        var data = {
            "userId": userId,
            "tagId":tagId,
            "content": processContent,
            "pics":pics
           // "latitude": 1.000000,        //position.coords.latitude,
          //  "longitude": 1.000000     //position.coords.longitude
        };
        $.ajax({
            type: "post",
            url:'/api/v1/feedService/create',      //编辑历程接口
            data: data,
            success: function (data) {
                $('#showerror1 p ').text('添加历程成功');
                $("#showerror1").fadeIn(1500, function () {
                    $(this).fadeOut(1500, function () {
                        return false;
                    });
                })
                $('#addProcess').css('display', 'none');
                $('#pasonnalPage').css('display', 'block');
                $("#rec_Img").attr("src",headUrl)
                window.location.href="/h5/user/personal?id="+userId+"&url=1";
            },
            error: function (msg) {
                alert("请求失败！");
                console.log(msg)
            }
        });
        /*    $.ajax({
         type: "get",
         url: '/api/v1/feedService/like/create',
         data:data,
         success: function (data) {
         $('#share .dianzan img').attr('src','../static/h5/images/dianzan.png');
         alert("点赞成功！");
         //likeCount=likeCount+1;
         //alert("点数量增加1");
         if(redCode == 1){
         isLike = !isLike;
         }
         },
         error: function (msg) {
         alert('请求失败');
         console.log(msg)
         }
         });
         }*/
    }
/*    function initPage(data) {
        //接口暂时不可以

        //个人分享列表
        //listShare(maxId, pageSize, sinceId, tagId, userId)
    }*/

/*
//个人分享列表
    function listShare(maxId, pageSize, sinceId, tagId, userId) {
        var data = {
            "maxId": maxId,
            "pageSize": pageSize,
            "sinceId": sinceId,
            "tagId": tagId,
            "userId": userId
        };
        $.ajax({
            type: "get",
            url: '/api/v1/feedService/get/userList',
            data: data,
            success: function (data) {
                shareList = data.data;
                $.each(shareList, function (key, value) {
                    //加载个人分享列表详情
                    var $li = $('<li class="container"></li>');
                    var $row1 = $('<div class="row"></div>');
                    var $row2 = $('<div class="row share-method"></div>');
                    var $rowContent1 = $('<div class="col-xs-6 share-time"></div>' +
                        '<div class="col-xs-6 share-content"></div>');
                    var $rowContent2 = $('<div class="col-xs-6 dianzan"></div>' +
                        '<div class="col-xs-6 comment"></div>');
                    var $share_time = $('<div><span class="share-time-day"></span>' +
                        '<span class="share-time-mouth"></span>月</div>');
                    var $share_content = $('<img src="/images/share-img.png" class="share-img" alt=""/>' +
                        '<span class="share-text">value.content</span>');
                    var $dianzan = $('<img src="/images/dianzan1.png" alt=""/>' +
                        '<span class="dianzan-count">value.likeCount</span>');
                    var $comment = $('<img src="/images/pinglun.png" alt=""/>' +
                        '<span class="pinglun-count">value.commentCount</span>');
                    $('.share-time').append($share_time);
                    $('.share-content').append($share_content);
                    $('.dianzan').append($dianzan);
                    $('.comment').append($comment);
                    $row1.append($rowContent1);
                    $row2.append($rowContent2);
                    $li.append($row1);
                    $li.append($row2);
                    $('#share ul').append($li);
                    //个人分享详情结束
                    feedId = value.feedTag.id;
                });

            },
            error: function (msg) {
                alert('请求失败');
                console.log(msg)
            }
        });
    }
*/

//发送分享
 /*   $(".share_btn").click(createShare);*/
//点赞or取消赞
    $('.dianzan').click(isLike);

//创建评论
  //  $('.comment').click(commentEdit);

/*//查看帖子详情
    $('#share .container').click(shareDetail);
//个人页面分享页面创建分享
        function createShare(){
            $("#pasonnalPage").hide();
            $("#publish").show();

            $(".cancle_share").on("click",function(){
                $("#pasonnalPage").show()
                $("#publish").hide()
            })

            $(".issue_share button").on("click",function(){
                if($(".share_cont").val()==""){
                    $(".issue_share button").attr({
                        "disabled":false
                    })
                }else{
                    $("#share ul li").remove()
                    $("#pasonnalPage").show()
                    $("#publish").hide()

                    var issMonth,issDay
                    var issFont = $(".share_cont").val()
                    var data = {
                        "issFont":issFont,
                        "issMonth":issMonth,
                        "issDay":issDay,
                    }
                    $.ajax({
                        type: "get",
                        url: '/h5/feed/feedDetail?userId=1&id=6&tagid=5',//接口地址？
                        data: data,
                        success: function (data) {
                            console.log('请求成功');
                        },
                        error: function (msg) {
                            console.log('请求失败');
                            console.log(msg)
                        }
                    });

                }
            })
        }*/
/*//帖子详情
 function shareDetail(shareList) {
        var index = $(this).index();
        feedId = shareList[index].id;
        var data = {
            "feedId": feedId,
            "userId": userId
        };
        $.ajax({
            type: "get",
            url: '/api/v1/feedService/get/one',
            data: data,
            success: function (data) {

            },
            error: function (msg) {
                alert('请求失败');
                console.log(msg)
            }
        });

    }*/

//返回上一页
    function goback() {
        window.history.back();
    }
    //刷新本页
    function myrefresh(){
        window.location.reload();
    }

    //赞or取消赞
        function isLike(){
            var likeCount = $(this).children('.dianzan-count').text();
            var liked=$(this).children('.liked').val();
            var fid=$(this).children(".fid").val();
            var userId=localStorage.getItem("userId");
            //alert(userId);
            var obj=$(this)
            var data = {
                "customerId":userId,
                "id": fid,
            };
            if (liked==0){
                $.ajax({
                    type: "get",
                    url: '/api/v1/feedService/like/create',
                    data:data,
                    success: function (data) {
                        obj.children('img').attr('src','/static/h5/images/dianzan.png');
                       // alert("点赞成功！");
                        //点赞成功之后把值变成1
                        obj.children(".liked").val(1);
                        obj.children(".dianzan-count").text(" ");
                        likeCount=parseInt(likeCount)+parseInt(1);
                        obj.children('.feelicount').val(likeCount)
                        obj.children(".dianzan-count").text(likeCount);
                    },
                    error: function (msg) {
                        alert('请求失败');
                        console.log(msg)
                    }
                });
            }
            else{
                $.ajax({
                    type: "post",
                    url: '/api/v1/feedService/like/delete',
                    data:data,
                    success: function (data) {
                        obj.children('img').attr('src','/static/h5/images/dianzan1.png');
                       // alert("取消成功！");
                        obj.children(".liked").val(0);
                        obj.children(".dianzan-count").text(" ");
                        likeCount=likeCount-1;
                        obj.children('.feelicount').val(likeCount)
                        obj.children(".dianzan-count").text(likeCount);
                    },
                    error: function (msg) {
                        alert('请求失败');
                        console.log(msg)
                    }
                });
            }
        }


//新增评论
        function commentEdit() {
            var index = $(this).parents("li").index()//点击第几条数据的检索值
            var obj=$(this)
            var disCount = $(this).children('.pinglun-count').text();
            var liked=$(this).children('.liked').val();
            var userId=localStorage.getItem("userId");
            $(".cmt_cont").val("")//初始化

            $(".cmt_btm").animate({
                bottom: "0"
            }, 500)

            // 发表评论
            $("#cmt_issue").off("click").on("click",function () {
                var toArea = $("#share").children("ul").children("li").eq(index).find(".cmt_area")//添加数据位置
                console.log(toArea)
                var feedId = $(".fid").val()//评论
                var content = $(".cmt_cont").val()//内容
                var data ={
                    "userId":userId,
                    "content":content,
                    "id":feedId
                }
                if(content.trim().length==0 || content==null){
                    alert("请输入内容")
                    return false;
                }else{
                    $.ajax({
                        type:"post",
                        url:"/api/v1/feedService/comment/create",
                        data:data,
                        success:function(data){
                            name=data.data.customer.name
                            obj.children(".pinglun-count").text(" ");
                            disCount=parseInt(disCount)+parseInt(1)
                            obj.children(".pinglun-count").text(disCount);
                            toArea.prepend('<p class="issue_cont"><span class="issue_id">'+name+'</span><span>：</span><span>'+data.data.content+'</span></p>')
                            $(".cmt_area").animate({
                                bottom: "-40px"
                            },500)
                        },
                        error:function(err){
                            //alert("issue failed")
                        }

                    })
                }
            })

            return false
        }
//阻止事件冒泡
        $(".cmt_btm").on("click",function(){
            return false
        })

        $("body").on("click",function(){
            $(".cmt_btm").animate({
                bottom:"-40px"
            },500)
        })
//删除评论
$(".cmt_area").on("click",".issue_cont",function(){
    var obj = $(this)
    // $("body").css({
    // 	opacity:"0.5"
    // })
    $(".del_cmt").animate({
        bottom:"0"
    },300)
    var feedId=$(this).children(".commentId").val();
    var userId=localStorage.getItem("userId");
    var count=$(this).parent(".cmt_area").siblings(".share-method").children(".comment").children(".pinglun-count");
    var text=count.text();
    $(".del").on("click",function(){
        $(".del_cmt").animate({
            bottom:"-75px"
        },300)
        // @parm feedid,userId,
        var data={
            "customerId":userId,
            "commentId":feedId
        }
        $.ajax({
            type:"post",
            url:"/api/v1/feedService/comment/delete",
            data:data,
            success:function(data){
                obj.remove();
                count.text(" ");
                count.text(parseInt(text)-parseInt(1));
            },
            error:function (data) {

            }
        });
    })
    $(".cancle").on("click",function () {
        $(".del_cmt").animate({
            bottom:"-75px"
        },300)

    })
    $("body").on("click",function () {
        $(".del_cmt").animate({
            bottom:"-75px"
        },300)
    })
    return false
});


$("#up_Img").on("click",function(){
    $('#pasonnalPage').css('display', 'none');
    $('#addProcess').css('display', 'block');

    $(".popup").animate({
        bottom:"-220px"
    },1000)
    $(".frame_box textarea").val("")//清除之前样式
    $("#Img").attr("src","/static/h5/images/photo-load.png")

})
$('.add-process').click(function () {
    $('#pasonnalPage').css('display', 'none');
    $('#addProcess').css('display', 'block');
});
$('#addProcess .go-back').on('click', function () {
    $('#addProcess').css('display', 'none');
    $('#pasonnalPage').css('display', 'block');
});



$('#addEditor .go-back').on('click', function () {
    $('#addEditor').css('display', 'none');
    $('#pasonnalPage').css('display', 'block');
    $('.nav li:last').addClass('active').siblings().removeClass('active');
    return false
});
$('#dropdownMenus').on('click',function() {
    var userId = localStorage.getItem("userId");
    if (userId != 1) {
        $("#familys").toggle();
    } else {
        $('#accordion').toggle();
    }

})
//跳到新增人物编辑部分

$('.adds-editor').on('click', function() {
    $('#pasonnalPage').css('display', 'none');
    $('#addEditor').css('display', 'block');
});

//添加了遮罩层
$('.more-btn').click(function(){
    $('#zhezhaoceng').show();
    $('#close').show();
});
$('#zhezhaoceng').click(function(){
    $(this).hide();
    $('#close').hide();
});
$('#close').click(function(){
    $('#close').hide();
    $('#zhezhaoceng').hide();
});
//获取用户选择添加的亲人
$("#familys li").click(function(){
    liclick=$(this).val();
});

///点击分享图片
$(".share_btn").on("click", function() {
    $("#pasonnalPage").hide()
    $("#publish").show()
});

$(".cancle_share").on("click",function(){
    $("#pasonnalPage").show()
    $("#publish").hide()
})
//点击发送文字分享
$(".share_btn").on("touchstart",createShare);
$(".share_btn").on("touchend",function(){
    clearTimeout(timeout);
});
//长按分享文字
var timeout = undefined;
function createShare(){
    timeout = setTimeout(function() {
        $("#pasonnalPage").hide()
        $("#publish").show()
        $(".img_box").hide() //图片隐藏
        $(".share_box textarea").css({
            height:"150px"
        })

        $(".cancle_share").on("click",function(){
            $("#pasonnalPage").show()
            $("#publish").hide()
            $(".img_box").show() //图片显示
            $(".share_box textarea").css({
                height:"80px"
            })
        })
    }, 1000);
}
$(".delete-family").on("click",function () {
    //当前页面的用户
    var userId=$("personId").val();
    var data={
        "userId":userId
    }
    $.ajax({
        type:"post",
        url:"/h5/family/deletefamperson",
        data:data,
        success:function (request) {

        },
        error:function (err) {

        }

    })
})
$("#add_more").on("change",changeFiles)
var aFile;
var aUrl = [];
function changeFiles() {
    aFile = this.files
    if(aFile.length<9){
        for (var i = 0; i < aFile.length; i++) {
            uploadFile(aFile[i])
        }
    }else{
        alert(最多上传9张图片)
    }
}
function uploadFile(aFile){
    var url = "/api/v1/upload/";    //文件上传接口地址 ?type=3&id=1
    var xhr = new XMLHttpRequest();
    var fd = new FormData();
    xhr.open("post", url, true);
    xhr.onreadystatechange = function () {
        if (xhr.readyState == 4 && xhr.status == 200) {
            var imgUrl = xhr.responseText;
            aUrl.push(imgUrl)
            $(".img_place .img_container").remove();
            imgContainer(aUrl);

        }
    };
    fd.append('file', aFile);
    xhr.send(fd);
}
function imgContainer(aUrl){
    for (var j=0;j<aUrl.length;j++) {
        $(".img_place").prepend("<li class='img_container'><img src="+aUrl[j]+"></li>")
        console.log(j)
    }
}

$(".issue_share").on("click",function(){
    if($(".share_cont").val().trim()==""){
        // $(".issue_share button").attr({
        //     "disabled":false
        // })
        alert("说点什么吧..")
    }else{
        var issFont = $(".share_cont").val();   //获取历程内容
        var userId = localStorage.getItem("userId");
        var tagId = 4;//死的  历程类型id
        var pics=aUrl;
        var data = {
            "content":issFont,
            "userId":userId,
            "tagId":tagId,
            "pics":pics
        }
        console.log(pics.length)
        if (pics.length>8){
            alert("最多上传9张图片")
        }else{
            $.ajax({
                type: "post",
                url: '/api/v1/feedService/create',
                data: data,
                success: function (data) {
                    console.log('请求成功');
                    // $("#pasonnalPage").show()
                    // $("#publish").hide()
                    window.location.reload()
                },
                error: function (msg) {
                    console.log('请求失败');

                }
            });
        }


    }
})

//长按亲属删除
var timer = undefined;
$(".relation li").on("touchstart",function(){
    oDel = $(this)
    timer = setTimeout(function(){
        $(".relation_mask,.relation_pop").fadeIn(500)
        $(this).remove()
    },1000)
})
$(".relation li").on("touchend",function(){
    clearTimeout(timer)
})

$(".relation_cancle").click(function(){
    $(".relation_mask,.relation_pop").fadeOut(500)
})
//确认删除
$(".relation_sure").on("click",function(){
    var relationId=oDel.find(".relationId").val();
    var userId=localStorage.getItem("userId");
    var familyId=oDel.find(".pId").val();
    var data={
        "userId":userId,
        "familyId":familyId,
        "relationId":relationId
    }
    console.log(data)
    $.ajax({
        type:"post",
        url:"/api/v1/family/deleteperson",
        data:data,
        success:function(request){
            $(".relation_mask,.relation_pop").fadeOut(500)
            oDel.remove();
            console.log(request)
        },
        error:function (e) {
            $(".relation_mask,.relation_pop").fadeOut(500)
            console.log(e)
        }
    })
})

//从家族成员但中选择
$(".addMem").hide()
$(".addTo").click(function(){
    $(".addMem").slideToggle(500)
})

$(".addMem").on("click",".applay_people",function(){
    oAdd = $(this)
    $(".member_mask,.member_pop").fadeIn(500)
})

$(".member_cancle").click(function(){
    $(".member_mask,.member_pop").fadeOut(500)
})
$(".member_sure").click(function(){
    $(".member_mask,.member_pop").fadeOut(500)

})









//验证姓名
function isChinaName(name){
    var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
    return pattern.test(name);
}
// 验证手机号
function isPhoneNo(phone) {
    var pattern = /^1[34578]\d{9}$/;
    return pattern.test(phone);
}

//获取姓名的输入框 用改变事件进行验证
$("[name=lastname]").change(function(){
    var name=$(this).val();
    if(isChinaName(name)){
        
    }else{
        alert("输入不是汉字！")
    }
})
$("[name=fristname]").change(function(){
    var name=$(this).val();
    if(isChinaName(name)){

    }else{
        alert("输入不是汉字！")
    }
})
//手机号码验证
$("[name=tel]").change(function(){
    var tel=$(this).val();
    if(isPhoneNo(tel)){

    }else{
        alert("输入的不是电话号码！");
    }
})

//判断是否健在
$('#isAlive').on('click',function(){
    var checked=$("#isAlive").prop("checked");
    $("#isAlive").prop("checked", checked);    //checked返回true表示在世，false表示去世
    console.log(checked)
    if(!checked){
        $('.over-time').css('display','block');
    }else{
        $('.over-time').css('display','none');
    }
});




//用json请求 "/h5/person/addfamily"
// 参数是person的属性
$("#sureEdit").click(function(){
    //获取各个文本框的值
    //var customerId=$(".personId").val();
   // if(customerId==null || customerId==0){
     var customerId=localStorage.getItem("userId");
   // }

    var shidai=$("#shidai").val();
    var lastname=$("[name=lastname]").val();
    var fristname=$("[name=fristname]").val();
    var gender=$('input:radio:checked').val();
    var borntime=$("#processTime1").val();
    var tel=$("#tel").val();
    var wechat=$("#wx").val();
    var alive=0;
    $("#isAlive").each(function(){
        if(this.checked){
            alive=$(this).val();
        }
    });

    //判断手机号码输入是否准确
    var pattern = /^1[34578]\d{9}$/;
    var tels = pattern.test(tel);
    if(!tels){
        $('#showerror p').text("请输入正确的电话号码！");
        $("#showerror").fadeIn(2000, function () {
            $(this).fadeOut(2000);
        });
        return false;
    }
    var url="/h5/person/addfamily";
    var data={
        "userId":customerId,
        "liclick":liclick,
        "lastname":lastname,
        "fristname":fristname,
        "gender":gender,
        "alive":alive,
        "borntime":borntime,
        "tel":tel,
        "wechat":wechat,
        "shidai":shidai
    }
    $.post(url,data,function(request){
        window.location.reload()
        $("#addEditor").hide()
        $("#pasonnalPage").show()
        $(".defined_tab li").eq(2).addClass("active").siblings().removeClass("active")
       
    });

});

$(".defined_tab li").on("click",function(){
    $(this).addClass("active").siblings().removeClass("active")
    var index = $(this).index()
    console.log(index)
    $(".tab-content .tab-pane").eq(index).show().siblings().hide()
})
//跳转分享详情页
$(".share-content").on("click",function () {
    var feedId=$(this).siblings(".fid").val();
    var tagId=$(this).children(".tagid").val();
    details(feedId,tagId);
})
$(".comment").on("click",function () {
    var feedId=$(this).siblings(".dianzan").children(".fid").val();
    var tagId=$(this).children(".tagid").val();
    details(feedId,tagId);
})
//跳转分享结束
//查看历程详情

$(".historyDetail").on("click",function () {
    var tagId=$(this).children(".tagid").val();
    var feedId=$(this).children(".fid").val();
    details(feedId,tagId)
})

//
function details(feedId,tagId){
    var userId=localStorage.getItem("userId");
    var url="/h5/feed/feedDetail?userId="+userId+"&id="+feedId+"&tagid="+tagId;
    window.location.href=url;
}

//跳转个人详情

$(".personDetail").on("click",function () {
    var personId=$(".personId").val();
    var url="/h5/user/personformation?id="+personId
   $(this).attr("href",url);
})

//点击亲属查看亲属信息
$(".relations").on("click",function () {
    var userId=0;
    var personId=$(this).children(".pId").val();
    var url='/h5/user/personal?id='+userId+'&personId='+personId+"&url=1"
    $(this).attr("href",url);
})

//退出
$(".logout").on("click",function () {
    localStorage.removeItem("userId");
    localStorage.removeItem("username");
    localStorage.removeItem("personId");
    localStorage.removeItem("mobile");
})
//删除亲属
$(".delete-family").on("click",function () {
    //当前页面的用户
    var personId=$(".personId").val();
    var familyId=$(".familyId").val();
    window.location.href= "/h5/family/delete?personId="+personId+"&familyId="+familyId;
})
//查看家谱树
$(".showtree").on("click",function () {
    var familyId=$(".familyId").val();
    window.location.href="/h5/family/tree?familyId="+familyId;

})

//删除当前历程
$('.deleteProcess').on('click',function () {
  //  alert("删除成功");
    var fid=$(this).siblings(".historyDetail").children(".fid").val();
    var userId=localStorage.getItem("userId");
    var obj=$(this)
    console.log(fid);
    var data={
        "customerId":userId,
        "id":fid
    }

    $.ajax({
        type:"post",
        data:data,
        url:"/api/v1/feedService/delete",
        success:function (request) {
            obj.parent(".up_box").remove();
        },
        error:function (mess) {
            
        }
    })

})
//返回上一级
$(".black").on("click",function () {
    var userId=localStorage.getItem("userId");
    var url="/h5/user/mzone?userId="+userId
    $(this).attr("href",url);
})

//兼容ios，bootstrap下拉菜单不兼容ios6plus
$(function(){
    $("#dropdownMenu").click(function(e) {});
});

//创建亲属手风琴效果
$(function() {
    var Accordion = function(el, multiple) {
        this.el = el || {};
        this.multiple = multiple || false;

        // Variables privadas
        var links = this.el.find('.link');
        // Evento
        links.on('click', {el: this.el, multiple: this.multiple}, this.dropdown)
    }

    Accordion.prototype.dropdown = function(e) {
        var $el = e.data.el;
        $this = $(this),
            $next = $this.next();

        $next.slideToggle();
        $this.parent().toggleClass('open');

        if (!e.data.multiple) {
            $el.find('.submenu').not($next).slideUp().parent().removeClass('open');
        };
    }

    var accordion = new Accordion($('#accordion'), false);
});

//跳转到手动添加的页面
$(".editor").on("click",function () {
    var familyId=$(".familyId").val();
    var relactionId=$(this).parent('li').val();
    var personId=$(".personId").val();
    var url="/h5/person/addfamilybyadmin?familyId="+familyId+"&relactionId="+relactionId+"&personId="+personId;
    $(this).attr("href",url);
})

